package bill.java.interview.fibonacci;

public class GenericFibonacci {
	private static int[] fib;
	private static int[] sum;
	static {
		fib = new int[64];
		sum = new int[64];
	}

	static int fibnocci(int n, int k) {

		fib[0] = 1;
		sum[0] = 1;
		for (int i = 1; i < n; i++) {
			if(i < k){
				fib [i] = fib [0];
				for(int j = 1; j < i ; j ++)
				fib[i] += fib[j];
			}
			for(int j = 0; j < k; j ++){
				fib[i] = fib[i] + fib[j];
			}
		}
		return 0;

	}

	/**
	 * iterative fibonacci
	 */
	int iterativeFib(int n) {
		int fib0 = 0;
		int fib1 = 1;
		int result = 0;
		for (int i = 2; i < n; i++) {
			result = fib0 + fib1;
			fib0 = fib1;
			fib1 = result;
		}
		return result;
	}

	/***
	 * recursive fibonacci
	 */
	int recursiveFib(int n) {
		if(n < 0){
			throw new IllegalArgumentException("The input parameter cannot be negative.");
		}
		if (n == 0) {
			return 0;
		} else if (n == 1) {
			return 1;
		} else {
			return recursiveFib(n - 1) + recursiveFib(n - 2);
		}
	}
}
